<?php
namespace Admin\Controller;
use Think\Controller;
 


 class CatController extends Controller {
 	public function add(){
 		if(!IS_POST){
 		     $this->display();
 		}else{
 		    $cat = D('Home/Cat');
 		    echo $cat->add($_POST)?'ok':'fail';
 		}
 	}

 	public function lists(){
 		$cat = D('Home/Cat');
 		$cats = $cat ->getTree();
 		//print_r($cats);exit;
                     $this->assign('cats',$cats);
                     $this->display();
 	}

 	public function edit(){
 		$cat = D('Home/Cat');
 		$cats = $cat->getTree();

                     $this->assign('cats',$cats);

 		$row = $cat ->find(I('get.cat_id'));//获取点击栏目id

 		if(empty($row)){
 			$this->redirect('Admin/Cat/lists');
 		}


 		if(!IS_POST){
 			$this->assign('row',$row);
 			$this->display();
 		}else{
 			//print_r($_POST);
 			//echo $cat->save()?'ok':'fail';
 			//save()传值优先权要高
 			echo $cat->where('cat_id='.I('get.cat_id'))->save($_POST)?'ok':'fail';
 			//$cat->cat_name = I('post.cat_name');
 			//$cat->intro =I('post.intro');
 			//echo $cat->save() ? 'ok' : 'fail';
 		}
 	}
 }
















